<template>
  <PageWrapper title="" contentFullHeight fixedHeight :loading="loading">
    <div class="text-center bg-white p-20px h-full">
      <div>
        <a-button @click="handleClear1">清空系统（含用户及权限）</a-button>
        <a-button class="ml-2" @click="handleClear2">清空系统（不含用户及权限）</a-button>
      </div>
      <div class="mt-2">(注：清除时将不会清除已设计的流程)</div>
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { h, ref } from 'vue';
  import { PageWrapper } from '/@/components/Page';
  import { getAdminClearSys } from '/@/api/system/system';
  import { useMessage } from '/@/hooks/web/useMessage';
  const { createMessage, createConfirm } = useMessage();
  const loading = ref(false);
  const handleClear1 = async () => {
    createConfirm({
      iconType: 'warning',
      title: () => h('span', '确定清空系统（含用户及权限）吗？'),
      onOk: async () => {
        try {
          loading.value = true;
          await getAdminClearSys(true);
          createMessage.success('操作成功');
          loading.value = false;
        } catch (error) {
          loading.value = false;
        }
      },
    });
  };
  const handleClear2 = async () => {
    createConfirm({
      iconType: 'warning',
      title: () => h('span', '确定清空系统（不含用户及权限）吗？'),
      onOk: async () => {
        try {
          loading.value = true;
          await getAdminClearSys(false);
          createMessage.success('操作成功');
          loading.value = false;
        } catch (error) {
          loading.value = false;
        }
      },
    });
  };
</script>
